package model;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Paper {
	protected int pid = 0;
	protected String title = null;
	protected int timeout = 40;
	protected int question_num = 0;
	protected int author_id = 0;
	protected int total_score = 0;
	
	public int getPid() {
		return pid;
	}
	
	public void setPid(int pid) {
		this.pid = pid;
	}
	
	public String getTitle() {
		return title;
	}
	
	public void setTitle(String title) {
		this.title = title;
	}
	
	public int getTimeout(){
		return this.timeout;
	}
	
	public void setTimeout(int timeout){
		this.timeout = timeout;
	}
	
	public int getQuestionNum() {
		return question_num;
	}
	
	public void setQuestionNum(int num) {
		this.question_num = num;
	}
	
	public int getAuthorId(){
		return this.author_id;
	}
	
	public void setAuthorId(int id){
		this.author_id = id;
	}
	
	public int getTotalScore(){
		return this.total_score;
	}
	
	public void setTotalScore(int score){
		this.total_score = score;
	}
	
	public static Paper fromDatabase(ResultSet rs){
		Paper p = new Paper();
		try{
			p.setPid(rs.getInt(1));
			p.setTitle(rs.getString(2));
			p.setQuestionNum(rs.getInt(3));
			p.setTimeout(rs.getInt(4));
			p.setAuthorId(rs.getInt(5));
			p.setTotalScore(rs.getInt(6));
		}catch(SQLException e){
			e.printStackTrace();
		}
		
		return p;
	}
}
